namespace SampleApp.Tests.Pages {
    using Microsoft.Services.TestTools.UITesting.Html;
    using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;

    [ClearCookies]
    [ClearCache]
    [BaseUri("Shop")] //to demonstrate the base uri attribute
    public class Shop : Page {
        
        public Shop AddProduct() {
            Browser.ClickOnButton("Add product");
            return this;
        }

        public Shop AddCartItem(int rowInstance, string categoryName, string productName, int quantity) {
            
            var row = Browser
                .Find<HtmlTable>()
                .Find<HtmlRow>().Instance(rowInstance);

            row
                .Find<HtmlComboBox>().Instance(1)
                .SelectedItem = categoryName;

            row
                .Find<HtmlComboBox>().Instance(2)
                .SelectedItem = productName;

            row
                .Find<HtmlEdit>()
                .Text = quantity.ToString();

            return this;
        }

        public Shop SubmitOrder() {
            Browser.ClickOnButton("Submit order");
            return this;
        }

        public bool MessageIsNotEmpty() {
            return !string.IsNullOrEmpty(
                Browser.Find<HtmlSpan>("data-bind","text: message").GetInnerText()
            );
        }
    }
}